/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpaintball;

import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

/**
 *
 * @author ondra
 */
public class LocalClient implements Observer {

    Game game;
    Canvas canvas;
    int playerIndex;
    InputController input;

    LocalClient(Game g, Canvas c) {
        game = g;
        canvas = c;

        input = new InputController();

        game.addObserver(this);
        playerIndex = game.addPlayer();

    }

    public void setKeys(KeyEvent e) {
        input.setKeys(e);
        setPlayerInput();
    }
    public void resetKeys(KeyEvent e) {
        input.resetKeys(e);
        setPlayerInput();
    }
    public void setMousePosition(int x, int y) {
        input.setMousePosition(x, y);
        setPlayerInput();
    }
    public void shoot() {
        game.shoot(playerIndex);
    }

    public void update(Observable o, Object _objects) {
        canvas.drawObjects((ArrayList)_objects);
    }
    private void setPlayerInput() {
        game.setPlayerInput(input, playerIndex);
    }

}
